﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public partial class BossListScene : Scene
{
	long currentRaidBossModelId = 0;
	GameObject raidBossModel = null;
	DBossReward[] bossReward;
	DBossCharTrait[] bossCharTrait;
	Dictionary<long, DBoss_New> bossDataDictionary = new Dictionary<long, DBoss_New>();
	Dictionary<long, GameObject> raidBossModelObjectDictionary = new Dictionary<long, GameObject>();
	
	public GameObject defaultBossBlankView;
	public GameObject suppressBossBlankView;

	public UILabel findRewardLabel;
	public UILabel joinRewardLabel;
	public UILabel suppressRewardLabel;

	public UIPanel defaultBossListPanel;
	public UIPanel suppressBossListPanel;

	public void SwitchTab(UIToggle toggle)
	{
		EPToggle epToggle = toggle.GetComponent<EPToggle>();
		epToggle.OnChangeProcess(UIToggle.current.value ? true : false);

		Debug.Log ("SwitchTab : " + epToggle.toggleIndex);

		if (!UIToggle.current.value)
			return;

		switch(epToggle.toggleIndex)
		{
		case 0:
			if (raidBossModel != null)
				raidBossModel.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);

			defaultBossListPanel.gameObject.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
			suppressBossListPanel.gameObject.transform.localPosition = new Vector3(9999.0f, 0.0f, 0.0f);

			LoadDefaultBossList();
			break;

		case 1:
			if (raidBossModel != null)
				raidBossModel.transform.localPosition = new Vector3(9999.0f, 0.0f, 0.0f);

			defaultBossListPanel.gameObject.transform.localPosition = new Vector3(9999.0f, 0.0f, 0.0f);
			suppressBossListPanel.gameObject.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);

			LoadSuppressBossList();
			break;
		}
	}

	public override void AwakeScene ()
	{
		NGUITools.SetActive(rewardGroup, false);

		bossCharTrait = GameData.Inst.bossCharTrait;
		bossReward = GameData.Inst.bossReward;

		//LoadDefaultBossList();
		InitBossData();
	}

	public override void StartScene ()
	{
		base.StartScene ();
	}

	void InitBossData()
	{
		foreach(DBoss_New bd in GameData.Inst.bossData)
		{
			if (bossDataDictionary.ContainsKey(bd.bossID))
				continue;

			bossDataDictionary.Add(bd.bossID, bd);
		}
	}

	void AddRaidBossModelObject(long id)
	{
		if (raidBossModelObjectDictionary.ContainsKey(id))
			return;

		GameObject raidBossModelObject = GameObject.Instantiate(Resources.Load ("Prefab/BossModel/BossModel_" + id.ToString()), Vector3.zero, Quaternion.identity) as GameObject;
		raidBossModelObject.SetActive(false);
		raidBossModelObjectDictionary.Add(id, raidBossModelObject);
	}

	void DeactivateRaidBossModel()
	{
		if (currentRaidBossModelId == 0)
			return;

		raidBossModelObjectDictionary[currentRaidBossModelId].SetActive(false);
		currentRaidBossModelId = 0;
	}

	void ActivateRaidBossModel(long id)
	{
		if (currentRaidBossModelId == id)
			return;

		if (raidBossModelObjectDictionary.ContainsKey(id))
		{
			if (currentRaidBossModelId != 0)
				raidBossModelObjectDictionary[currentRaidBossModelId].SetActive(false);

			currentRaidBossModelId = id;
			raidBossModelObjectDictionary[id].SetActive(true);
		}
	}

	public void DisplayRaidBossModel(int indexPath)
	{
		findRewardLabel.text = defaultBossRewardList[indexPath][0];
		joinRewardLabel.text = defaultBossRewardList[indexPath][1];
		suppressRewardLabel.text = defaultBossRewardList[indexPath][2];
		NGUITools.SetActive(rewardGroup, true);
		ActivateRaidBossModel(defaultBossList[indexPath].raidBossId);
	}

	public void OnClick_CloseAll()
	{
		PopupManager.PopPopup();
	}

}
